package chapter6;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 * Created by uu on 2017/6/23.
 */
public class load_balancing_producer2 {
    public static void main(String[] args) throws Exception{
        ConnectionFactory factory =  new ConnectionFactory();
        factory.setUsername("alert_user");
        factory.setPassword("alertme");
        factory.setVirtualHost("/");
        factory.setHost("localhost");
        factory.setPort(5670);
        Connection conn = factory.newConnection();
        final Channel channel = conn.createChannel();
        channel.exchangeDeclare("balance-exchange2","direct",true,false,null);
        channel.queueDeclare("balance-queue2",false,false,false,null);
        channel.queueBind("balance-queue2","balance-exchange2","balance2",null);
        for(int i=0;i<10;i++) {
            channel.basicPublish("balance-exchange2", "balance2", true, null, String.valueOf(i).getBytes() );
        }
        channel.close();
        conn.close();
    }
}
